<?php

namespace app\tours\controller;

class Index extends Common {

        public function index() {

                //幻灯片
                $slide = M("Slide")->field(true)->where(array('type' => 1))->order("sort desc")->limit(6)->select();
                $spic = array();
                foreach ($slide as $key => $value) {
                        $lian = explode('/', $value['url']);
                        $value['url'] = $lian[1];
                        $spic[$key] = $value;
                }
                $this->assign("spic", $spic);

                //首推部分
                $Tours = D('Tours');
                $where = array('ischecked' => 1, 'isnotshow' => 0, 'isdelete' => 0, 'isindex' => 1);
                $shoutui = $Tours->field(true)->where($where)->order("dateline desc")->limit(4)->cache(true)->select();
                $this->assign('shoutui', $shoutui);
                //旅游攻略
                $gonglue = D("News")->where(array('ischecked' => 1, 'cid' => 1))->order('id desc')->limit(3)->cache(true)->select();
                $this->assign('gonglue', $gonglue);
                //旅游资讯
                $zixuns = D("News")->where(array('ischecked' => 1, 'cid' => 2))->order('id desc')->limit(6)->cache(true)->select();
                $this->assign('zixun', $zixuns);
                //景点管理
                $where_jd = array('status' => 1, 'istop' => '1');
                $jingdian = D('Jingdian')->where($where_jd)->relation(true)->limit(5)->cache(true)->select();
                $this->assign('jingdian', $jingdian);

                //一日游
                $where_xiaxuan = array('isgood' => 1, 'ischecked' => 1, 'isnotshow' => 0, 'isdelete' => 0);
                $xiaxuan = D('Tours')->field(true)->relation(true)->where($where_xiaxuan)->cache(true)->select();
                $yirouyou = array();
                foreach ($xiaxuan as $key => $val) {
                        //一日游
                        if ($val['trip_days'] == 1) {
                                $yiriyou[$key] = $val;
                        }
                        //二日游
                        if ($val['trip_days'] == 2) {
                                $erriyou[$key] = $val;
                        }
                        if ($val['trip_days'] == 3) {
                                $sanriyou[$key] = $val;
                        }
                        if ($val['trip_days'] == 4) {
                                $siriyou[$key] = $val;
                        }
                        if ($val['trip_days'] == 5) {
                                $wuriyou[$key] = $val;
                        }
                }
                if (!empty($yiriyou)) {
                        $this->assign('yiriyou', $yiriyou);
                }
                if (!empty($erriyou)) {
                        $this->assign('erriyou', $erriyou);
                }
                if (!empty($sanriyou)) {
                        $this->assign('sanriyou', $sanriyou);
                }
                if (!empty($siriyou)) {
                        $this->assign('siriyou', $siriyou);
                }
                if (!empty($wuriyou)) {
                        $this->assign('wuriyou', $wuriyou);
                }
                //SEO优化，生成TITLE,K,D
                $this->assign('seo_title', C('site.index_seotitle'));
                $this->assign('seo_keywords', C('site.index_seokeywords'));
                $this->assign('seo_description', C('site.index_seodescription'));


                return $this->fetch();
        }

}
